import java.util.ArrayList;
import java.util.List;

public class B3 {

    private enum State {
        IDLE,               // 初始状态
        READING_STRING,     // 读取字符串状态
        ESCAPE_SEQUENCE,    // 转义字符处理状态
        END_STRING          // 字符串结束状态
    }

    public static List<String> extractStrings(String sourceCode) {
        List<String> strings = new ArrayList<>();
        StringBuilder currentString = new StringBuilder();
        State currentState = State.IDLE; // 初始状态

        for (int i = 0; i < sourceCode.length(); i++) {
            char currentChar = sourceCode.charAt(i);

            switch (currentState) {
                case IDLE:
                    if (currentChar == '"') {
                        currentState = State.READING_STRING; // 开始读取字符串
                    }
                    break;

                case READING_STRING:
                    if (currentChar == '\\') {
                        currentState = State.ESCAPE_SEQUENCE; // 转义字符
                    } else if (currentChar == '"') {
                        strings.add(currentString.toString()); // 结束字符串，保存
                        currentString.setLength(0); // 清空当前字符串
                        currentState = State.END_STRING; // 结束字符串读取
                    } else {
                        currentString.append(currentChar); // 正常字符，添加到当前字符串
                    }
                    break;

                case ESCAPE_SEQUENCE:
                    currentString.append(currentChar); // 转义字符后的字符直接加入字符串
                    currentState = State.READING_STRING; // 继续读取字符串
                    break;

                case END_STRING:
                    if (currentChar == '"') {
                        currentState = State.READING_STRING; // 继续读取下一个字符串
                    }
                    break;
            }
        }

        return strings;
    }

    public static void main(String[] args) {
        String sourceCode = "Some code here \"This is a string with \\\"escaped quotes\\\"\" and more code \"Another string here!\"";
        List<String> extractedStrings = extractStrings(sourceCode);

        System.out.println("Extracted Strings:");
        for (String str : extractedStrings) {
            System.out.println(str);
        }
    }
}
